package com.yh.controller.api;

import com.yh.entity.Brand;
import com.yh.service.CinemaService;
import com.yh.utils.Constants;
import com.yh.vo.CustomPageAndNavigate;
import com.yh.vo.CinemaVO;
import com.yh.vo.HallVO;
import com.yh.vo.ResponseVO;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author yuhuan
 * @date 2022/01/13
 */
@RestController
@RequestMapping("/api/cinema")
public class CinemaWeb {
    @DubboReference(check = false)
    private CinemaService cinemaService;

    /**
     * 查询所有的影院品牌
     * 服务地址 http://localhost:8080/api/cinema/brand/all
     */
    @RequestMapping("/brand/all")
    public ResponseVO findCinemaBrandAll() {
        List<Brand> brands = cinemaService.findCinemaBrandAll();
        return ObjectUtils.isEmpty(brands) ? ResponseVO.buildSuccessInstance(Constants.ResponseDataState.NULL_RESULT) :
                ResponseVO.buildSuccessInstance(brands);
    }

    /**
     * 根据影片的ID、影院的品牌和日程搜索符合要求的影院列表
     * 服务地址 http://localhost:8080/api/cinema/list?movieId=1&dateSign=-1&brandId=0
     */
    @RequestMapping("list")
    public ResponseVO seachCinemaListByMovieIdAndBrandAndSchedule(@RequestBody CinemaVO cinemaVO) {
        CustomPageAndNavigate page = cinemaService.seachCinemaByMovieIdAndBrandAndSchedule(cinemaVO);
        return ObjectUtils.isEmpty(page) ? ResponseVO.buildSuccessInstance(Constants.ResponseDataState.NULL_RESULT) :
                ResponseVO.buildSuccessInstance(page);
    }

    /**
     * 根据影院ID查找影院详情（影院基本信息+影院服务+影院播放的所有影片）
     * 服务地址 http://localhost:8080/api/cinema/detail?cinemaId=1
     */
    @RequestMapping("detail")
    public ResponseVO findCinemaDetailById(int cinemaId) {
        CinemaVO cinemaVO = cinemaService.findCinemaDetailById(cinemaId);
        return ObjectUtils.isEmpty(cinemaVO) ? ResponseVO.buildSuccessInstance(Constants.ResponseDataState.NULL_RESULT) :
                ResponseVO.buildSuccessInstance(cinemaVO);
    }

    /**
     * 根据影厅ID查找影厅详情（影厅基本信息+影厅类型+影厅布局）
     * 服务地址 http://localhost:8080/api/cinema/hall/detail?hallId=3
     */
    @RequestMapping("/hall/detail")
    public ResponseVO findHallDetailById(int hallId) {
        HallVO hallVO = cinemaService.findHallDetailById(hallId);
        return ObjectUtils.isEmpty(hallVO) ? ResponseVO.buildSuccessInstance(Constants.ResponseDataState.NULL_RESULT) :
                ResponseVO.buildSuccessInstance(hallVO);
    }
}
